﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        <select class="form-control " id="Region" col="Region">
                        </select>
                    </li>
                    <li>
                        <select class="form-control " id="DetectionType" col="DetectionType">
                            <option value="-1">检测类型 </option>
                            <option value="0">初检 </option>
                            <option value="1">常规复检 </option>
                        </select>
                    </li>
                    @*<li>
                            <select class="form-control " id="DetectionStatus" col="DetectionStatus">
                                <option value="-1">检测状态 </option>
                            </select>
                        </li>
                        <li>
                            <select class="form-control " id="AuditStatus" col="AuditStatus">
                                <option value="-1">审核状态 </option>
                            </select>
                        </li>*@
                    <li>
                        <input id="keywords" col="keywords" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group" id="toolbar">
            <a id="btnAdd" class="btn btn-default" onclick="showSaveForm()"><i class="fa fa-plus"></i> 复检</a>
            <a id="btnMInfo" class="btn btn-default" onclick="showInfoForm()"><i class="fa fa-truck"></i> 机械信息</a>
            <a id="btnReport" class="btn btn-default" onclick="showSurveyReport()"><i class="fa fa-archive"></i> 检测报告</a>
            <a id="btnVideo" class="btn btn-default" onclick="showVideo()"><i class="fa fa-video-camera"></i> 检测视频</a>
            <a id="btnCert" class="btn btn-default" onclick="showDeviceCert()"><i class="fa fa-vcard-o"></i> 合格证</a>
            <a id="btnShowGps" class="btn btn-default" onclick="showGps()"><i class="fa fa-map-marker"></i> 查看GPS</a>
            <a id="btnProcess" class="btn btn-default" onclick="showProcessData()"><i class="fa fa-file-text-o"></i> 检测过程数据</a>
            <a id="btnAudit" class="btn btn-default " onclick="showAuditTask()"><i class="fa fa-check"></i> 审核</a>
            <a id="btnUpload" class="btn btn-default " onclick="doUpload()"><i class="fa fa-upload"></i> 上传环保局</a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var detectionStatus=@ViewBag.DetectionStatus;
    $(function () {
        if (detectionStatus != 1) {
            $("#btnVideo").hide();
            $("#btnCert").hide();
            $("#btnAudit").hide();
            $("#btnReport").hide();
            $("#btnProcess").hide();
        }
         initComboBox('Region', 'Region');
        //initComboBox('AuditStatus', 'AuditStatus');
        //initComboBox('DetectionStatus', 'DetectionStatus');
        initGrid();
    });
    function initComboBox(dictType,OwnerId) {
        var list = top.getDataDict(dictType);
        if (list) {
            for (var i = 0; i < list.length; i++) {
                $('#' + OwnerId).append('<option values="' + list[i].DictKey + '">' + list[i].DictValue + '</option>');
            }
        }
    }
    function initGrid() {
        var queryUrl = '@Url.Content("~/YiDongYuan/DetectionTask/GetPageListJson")' + '?DetectionStatus=@ViewBag.DetectionStatus';
        $('#gridTable').ysTable({
            url: queryUrl,
            sortName: 'DetectionTime',
            sortOrder: 'Desc',
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'MechanicsId', title: 'MechanicsId', visible: false },
                { field: 'IsUp2Hzx', title: 'IsUp2Hzx', visible: false },
                { field: 'SiteVideo', title: 'SiteVideo', visible: false },
                { field: 'DetectionInfoId', title: 'DetectionInfoId', visible: false },
                {
                    field: 'DetectionType', title: '检测类型', formatter: function (value, row, index) {
                        return top.getDataDictValue('DetectionType', value);
                    }
                },
                {
                    field: 'DetectionStatus', title: '检测状态', formatter: function (value, row, index) {
                        return top.getDataDictValue('DetectionStatus', value);
                    }
                },
                { field: 'HuanBaoCode', title: '环保号牌' },
                { field: 'DetectionUserName', title: '检测人' },
                {
                    field: 'DetectionTime', title: '检测时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    field: 'DetectionInfoResult', title: '检测结果', formatter: function (value, row, index) {
                        return top.getDataDictValue('DetectionInfoResult', value);
                    }
                },
                {
                    field: 'DetectionInfoResultDPQ', title: '低排区', formatter: function (value, row, index) {
                        return top.getDataDictValue('DetectionInfoResult', value);
                    }
                },
                { field: 'AuditUserName', title: '审核人' },
                {
                    field: 'AuditTime', title: '审核时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    } },
                {
                    field: 'AuditStatus', title: '审核结果', formatter: function (value, row, index) {
                        return top.getDataDictValue('AuditStatus', value);
                    }
                },
                { field: 'AuditReason', title: '审核说明' },
                {
                    field: 'IsUp2Hzx', title: '环保局', formatter: function (value, row, index) {
                        if (value == 1) {
                            return '√';
                        } else if (value == 0) {
                            return '';
                        }
                        return value;
                    }
                },

            ],
            singleSelect: true,
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }
    //审核
    function showAuditTask() {
        var id = 0;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            id = selectedRow[0].Id;
        }
        var auditStatus = selectedRow[0].AuditStatus;
        if (auditStatus==1) {
            ys.alertError('请勿重复审核');
            return;
        }

        ys.openDialog({
            title: '审核',
            content: '@Url.Content("~/YiDongYuan/DetectionTask/ShowAuditTask")' + '?id=' + id,
            width: '800px',
            height: '300px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }
    //非道机械合格证标志
    function showDeviceCert() {
        var id = 0;
        var status = 0;
        var result = -1;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            status = selectedRow[0].DetectionStatus;
            if (status == 0) {
                ys.alertError('该设备为未检测状态，无法查看合格证');
                return;
            }
            result = selectedRow[0].DetectionInfoResultDPQ;
            if (result != 0) {
                ys.alertError('该设备低排区检测结果为不合格，无法查看合格证');
                return;
            }

        }
        id = selectedRow[0].Id;
        ys.openDialog({
            title: '非道机械合格证标志',
            content: '@Url.Content("~/YiDongYuan/DetectionTask/DeviceCert")' + '?id=' + id,
            width: '800px',
            height: '550px',
            btn:null,
        });
    }
    //检测视频
    function showVideo() {
        var SiteVideo = "";
        var status = 0;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            SiteVideo = selectedRow[0].SiteVideo;
            status = selectedRow[0].DetectionStatus;
            if (status == 0) {
                ys.alertError('该设备为未检测状态，无法查看检测视频');
                return;
            }
        }
        ys.openDialogContent({
            title: '检测视频',
            content: '<video controls="controls" style="width:430px;height:480px"><source src="@Url.Content("https://jxhfd-api.sxxmlg.cn/File/Show?id=")' + SiteVideo+'" /></video>',
            width: '550px',
            height: '600px',
        });
    }
    //检测过程数据
    function showProcessData() {
        var id = 0;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            if (selectedRow[0].DetectionStatus == 0) {
                ys.alertError('该设备为未检测状态，无法查看检测过程数据');
                return;
            }
        }
        console.log(selectedRow[0]);
        id = selectedRow[0].DetectionInfoId;
        ys.openDialog({
            title: '检测过程数据',
            content: '@Url.Content("~/YiDongYuan/DetectionTask/ShowProcessData")' + '?id=' + id,
            width: '800px',
            height: '700px',
            btn:null,
        });
    }
    function showSurveyReport(id, mechanicsId) {
        var id = 0;
        var status = 0;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            status = selectedRow[0].DetectionStatus;
            if (status == 0) {
                ys.alertError('该设备为未检测状态，无法查看检测报告');
                return;
            }
        }
        id = selectedRow[0].Id;
        ys.openDialog({
            title: "非道路移动柴油机械排气烟度检验报告",
            content: '@Url.Content("~/YiDongYuan/DetectionInfo/CMAReport")' + '?id=' + id,
            width: "800px",
            isFull: true,
            btn: null
        });
    }
    //复检
    function showSaveForm() {
        ys.openDialog({
            title: '复检',
            content: '@Url.Content("~/YiDongYuan/DetectionTask/ShowRecheckForm")',
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }
    function showGps() {
        var id = 0;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            id = selectedRow[0].Id;
        }
         ys.openDialog({
            title: '查看GPS',
            content: '@Url.Content("~/YiDongYuan/Gps/ShowFromTask")' + '?id=' + id,
            width: '768px',
            height: '550px',
            isFull:true,
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
            }
        });
    }
    //机械信息
    function showInfoForm() {
        var id = 0;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            id = selectedRow[0].MechanicsId;
        }
        ys.openDialog({
            title: '机械信息',
            content: '@Url.Content("~/YiDongYuan/DetectionMechanics/DetectionMechanicsForm")' + '?id=' + id,
            width: '768px',
            height: '550px',
            isFull:true,
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }
    function doUpload() {
        var id;
        var status = 0;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            id = selectedRow[0].Id;
            status = selectedRow[0].AuditStatus;
            if (status != 1) {
                ys.alertError('未审核通过，无法上传');
                return;
            }
            var isUp2Hzx = selectedRow[0].IsUp2Hzx;
            if (isUp2Hzx == 1) {
                ys.alertError('已上传成功，请勿重复操作');
                return;
            }
        }
       ys.ajax({
                    url: '@Url.Content("~/YiDongYuan/DetectionTask/DoUpload")' + '?id=' + id,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/YiDongYuan/DetectionTask/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
